package com.aaa.day1107.demo02;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author ${崔灿}
 * @date 2022/11/07 16:39
 **/

public class Test {
    public static void main(String[] args) {
        //把日期转化为指定格式的字符串
        LocalDateTime now = LocalDateTime.now();
        System.out.println("转化前的日期时间："+now);
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = now.format(dtf);
        System.out.println("转化后："+format);

        //把字符串转化为日期时间对象
        DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateTime = LocalDateTime.parse("2020-11-17 22:22:22",dtf1);
        System.out.println(dateTime);

    }
}
